/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cs575.dbentities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author bms
 */
@Entity
@Table(name = "task_approval", catalog = "tasks_management", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "TaskAssign.findAll", query = "SELECT t FROM TaskAssign t"),
    @NamedQuery(name = "TaskAssign.findByTaskId", query = "SELECT t FROM TaskAssign t WHERE t.taskAssignPK.taskId = :taskId"),
    @NamedQuery(name = "TaskAssign.findBySourceUserId", query = "SELECT t FROM TaskAssign t WHERE t.taskAssignPK.sourceUserId = :sourceUserId"),
    @NamedQuery(name = "TaskAssign.findByDestUserId", query = "SELECT t FROM TaskAssign t WHERE t.taskAssignPK.destUserId = :destUserId"),
    @NamedQuery(name = "TaskAssign.findByIsApproved", query = "SELECT t FROM TaskAssign t WHERE t.isApproved = :isApproved")})
public class TaskAssign implements Serializable, ITaskAssign {
    private static final long serialVersionUID = 1L;
    
    @EmbeddedId 
    protected TaskAssignPK taskAssignPK;
    @Basic(optional = false)
    @Lob
    @Column(name = "comment", nullable = false, length = 65535)
    private String comment;
    @Basic(optional = false)
    @Column(name = "isApproved", nullable = false)
    private boolean isApproved;
    @JoinColumn(name = "dest_user_id", referencedColumnName = "user_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private User destUser;
    @JoinColumn(name = "source_user_id", referencedColumnName = "user_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private User sourceUser;
    @JoinColumn(name = "task_id", referencedColumnName = "task_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Task task;

    public TaskAssign() {
    }

    public TaskAssign(TaskAssignPK taskAssignPK) {
        this.taskAssignPK = taskAssignPK;
    }

    public TaskAssign(TaskAssignPK taskAssignPK, String comment, boolean isApproved) {
        this.taskAssignPK = taskAssignPK;
        this.comment = comment;
        this.isApproved = isApproved;
    }

    public TaskAssign(int taskId, int sourceUserId, int destUserId) {
        this.taskAssignPK = new TaskAssignPK(taskId, sourceUserId, destUserId);
    }

    public TaskAssignPK getTaskAssignPK() {
        return taskAssignPK;
    }

    public void setTaskAssignPK(TaskAssignPK taskAssignPK) {
        this.taskAssignPK = taskAssignPK;
    }

    @Override
    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    @Override
    public boolean getIsApproved() {
        return isApproved;
    }

    public void setIsApproved(boolean isApproved) {
        this.isApproved = isApproved;
    }


    @Override
    public User getDestUser() {
        return destUser;
    }

    public void setDestUser(User user) {
        this.destUser = user;
    }

    @Override
    public User getSourceUser() {
        return sourceUser;
    }

    public void setSourceUser(User user1) {
        this.sourceUser = user1;
    }

    @Override
    public Task getTask() {
        return task;
    }

    public void setTask(Task task) {
        this.task = task;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (taskAssignPK != null ? taskAssignPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TaskAssign)) {
            return false;
        }
        TaskAssign other = (TaskAssign) object;
        if ((this.taskAssignPK == null && other.taskAssignPK != null) || (this.taskAssignPK != null && !this.taskAssignPK.equals(other.taskAssignPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cs575.dbentities.TaskAssign[ taskAssignPK=" + taskAssignPK + " ]";
    }
    
}
